import React        from 'react';

import Nav          from '../../config/Navigator';
import Bowl         from '../icon/Bowl';
import history      from '../../utils/history';
import './empty.scss';

export default ({list, type, children}) => {

    if(!_.isEmpty(list)){
        return [children];
    }
    return <Empty {...emptyMap[type]}/>;

};

const btnMap = {
    voucher: {
        text: '兑换商城',
        click(){
            history.push(Nav.cartList());
        }
    }
};

const emptyMap = {
    'new': {
        btn: btnMap.voucher,
        label: '您还没有代金券！',
    },
    used: {
        btn: btnMap.voucher,
        label: '您还没有使用记录！',
    },
    expire: {
        btn: btnMap.voucher,
        label: '您还没有过期的兑换券！',
    },
    cart: {
        btn: btnMap.voucher,
        label: '购物车空空如也！',
    },
    record: {
        btn: btnMap.voucher,
        label: '您还没有兑换记录哦！',
    },
    accum: {
        btn: btnMap.voucher,
        label: '您还没有积分记录哦！',
    },
    store: {
        label: '您还没有下架商品！',
    },
};

const Empty = ({label, btn}) => (
    <div className="empty flex-avg">
        <div className="e-label">{label}</div>
        <div className="e-icon"><Bowl size="2rem"/></div>
        {btn && <div className="e-btn flex-avg" onClick={btn.click}>{btn.text}</div>}
    </div>
);
